package com.program.beautymakeup.controller.wxController;

import com.program.beautymakeup.domain.vo.PortfolioRsp;
import com.program.beautymakeup.domain.vo.ResultInfo;
import com.program.beautymakeup.service.HomeService;
import com.program.beautymakeup.utils.ResultInfoUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author bytedance
 * @ClassName HomeController.java
 * @Description 首页接口
 * @createTime 2023年02月09日 09:50:00
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/home")
public class HomeController {

    @Autowired
    private HomeService homeService;

    @GetMapping("/list")
    public ResultInfo getHomeList(@RequestParam(value = "pageNum", required = false) Integer pageNum,
                                  @RequestParam(value = "pageSize", required = false) Integer pageSize) {
        if (pageNum == null) {
            pageNum = 1;
        }
        if (pageSize == null) {
            pageSize = 15;
        }
        List<PortfolioRsp> portfolioRspList = homeService.getHomeList(pageNum, pageSize);
        return ResultInfoUtil.buildSuccess(portfolioRspList);
    }

    @GetMapping("/search")
    public ResultInfo search(@RequestParam(value = "keyword", required = false) String keyword) {
        return ResultInfoUtil.buildSuccess(homeService.search(keyword));
    }

    @GetMapping("/recentSearch")
    public ResultInfo recentSearch() {
        return ResultInfoUtil.buildSuccess(homeService.recentSearch());
    }

}
